package com.yangxd.hospital.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yangxd.hospital.entity.Department;
import com.yangxd.hospital.entity.Registration;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yangxd
 * @since 2021-05-07
 */
public interface RegistrationMapper extends BaseMapper<Registration> {

    @Select("select * from registration where user_id = #{userId}")
    List<Registration> getListById(Integer userId);

    @Insert("insert into registration(department_id,user_id,doctor_id,date,department_name,doctor_name,user_name,gender,type,age,place) VALUES" +
            "(#{departmentId},#{userId},#{doctorId},#{date},#{departmentName},#{doctorName}," +
            "#{userName},#{gender},#{type},#{age},#{place})")
    void saveRegistration(Registration registration);

    @Select("select * from registration where doctor_id = #{doctorId}")
    List<Registration> getListByDocId(Integer doctorId);

    @Update("UPDATE registration set `status` = #{status} where registration_id = #{registrationId}")
    void updateStatus(@Param("status") Integer status,@Param("registrationId") Integer registrationId);

    /**
     * 分页查询所有挂号记录
     * @param page
     * @param wrapper
     * @return
     */
    IPage<Registration> findPageRegistration(Page<Registration> page, @Param(Constants.WRAPPER) QueryWrapper<Registration> wrapper);

    /**
     *
     * @return
     */
    @Select("select count(1) from registration where doctor_id = #{doctorId} and status = 1")
    int selectNum(Integer doctorId);
}
